package com.alogic.cert.bc;

import org.bouncycastle.asn1.x509.KeyUsage;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;


/**
 * KeyUsageTools
 *
 * @since 1.6.13.40 [20210306 duanyy] <br>
 */
public class KeyUsageTools {
    private static Map<String, Integer> idValue = new HashMap<String,Integer>();

    public static Integer getByName(String name){
        return idValue.get(name);
    }

    static {
        Class<KeyUsage> clazz = KeyUsage.class;
        Field[] fields = clazz.getDeclaredFields();
        for (Field field:fields){
            int modifiers = field.getModifiers();

            if (Modifier.isPublic(modifiers)
                    && Modifier.isStatic(modifiers)
                    && Modifier.isFinal(modifiers)){
                try {
                    Object value = field.get(clazz);
                    if (value instanceof Integer) {
                        idValue.put(field.getName(), (Integer) value);
                    }
                } catch (IllegalAccessException e) {
                    continue;
                }
            }
        }
    }
}
